/* 
 * File:   Lcd.cpp
 * Author: ejordan
 * 
 * Created on March 21, 2013, 10:50 PM
 */

#include <p32xxxx.h>
#include <plib.h>
#include "Lcd.h"
#include "Pmp.h"

/*! \brief Creates a new instance of the Lcd class.
 */
Lcd::Lcd()
{
}

/*! \brief Initializes the Lcd class.
 */
void Lcd::Initialize()
{
	PMPSetAddress(0);
	PMPMasterWrite((unsigned short)Lcd::Commands::DataLength8Bit | (unsigned short)Lcd::Commands::DualLine); TMR1 = 0; while (TMR1 < 30);
	PMPMasterWrite((unsigned short)Lcd::Commands::DisplayOn); TMR1 = 0; while (TMR1 < 30);
	PMPMasterWrite((unsigned short)Lcd::Commands::DisplayClear); TMR1 = 0; while (TMR1 < 1000);
	PMPMasterWrite((unsigned short)Lcd::Commands::Increment);TMR1 = 0; while (TMR1 < 1000);
}

/*! \brief Writes a command to the LCD
 *
 * @param command
 */
void Lcd::WriteCommand(unsigned char command)
{
	PMPSetAddress(0);
	PMPMasterWrite(command);
	TMR1 = 0;
	while (TMR1 < 1000);

}

/*! \brief Writes data to the LCD
 *
 * @param data
 */
void Lcd::Write(unsigned char data)
{
	PMPSetAddress(1);
	PMPMasterWrite(data);
	TMR1 = 0;
	while (TMR1 < 1000);
}

/*! \brief Default destructor
 */
Lcd::~Lcd() { }

